<template>

  <div style="text-align: center;" id="login">
    <!--  background-image: url('${require('@/assets/etty.jpg')}'引入照片-->
    <!--      <div class="box" :style="`position: relative; background-image: url('${require('@/assets/etty.jpg')}');`">-->

    <el-card
        :style="`width: 500px;height: 600px; margin: auto;background-image: url('${require('@/assets/etty.jpg')}');`">
      <!--    <div @click="$router.push('/index')">返回首页</div>-->

      <div slot="header" style="font-size: 30px">
        <!--        首页图标-->
        <div style="text-align: right;float: right">
          <i class="el-icon-s-home" @click="$router.push('/index')" style="font-size: 1em;"></i>
        </div>
        欢迎来到lucky相册!
      </div>
      <el-form :model="user" :rules="rules" ref="loginForm" class="demo-ruleForm">
        <el-form-item label="账号" prop="account" style="font-size: 18px">
          <el-input style="width: 400px;background-color: rgba(248,248,248,0.5)" v-model="user.account"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password">
          <el-input style="width: 400px" v-model="user.password"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="login">登录</el-button>
          <a  @click="$router.push('/register')" style="cursor: pointer;margin: 10px;color: #3a8ee6">没有账号？去注册</a>
        </el-form-item>

      </el-form>
    </el-card>

  </div>

</template>

<script>

import axios from 'axios';

export default {
  name: "",
  data() {
    return {
      user: {},
      rules: {
        account: [
          {required: true, message: '请输入账号', trigger: 'blur'}
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'},
          {min: 1, max: 32, message: '长度在 1 到 32 个字符', trigger: 'blur'}
        ],
      }
    }
  },
  methods: {
    login() {
      this.$refs.loginForm.validate((r) => {
        if (r) {
          axios.post('http://localhost:8086/api/user/login', this.user).then(res => {
            console.log(res);
            if (res.data.status === 1) {
              localStorage.setItem('TOKEN', res.data.data.token);
              this.$router.push('/index');
            }

          })
        } else {
          this.$message.warning('请填完信息后再登录');
        }
      })
    }
  }
}
</script>

<style lang="scss">
//防止代码流失，在style里面放lang="scss"，再给div一个id="login"，文件名为什么ID名就命名为什么，最后把样式都放进这个ID里面
#login {
  .el-card__body {
    padding: 55px;
  }

  .el-card__header {
    padding: 17px 20px;
    border-bottom: 1px solid #EBEEF5;
    box-sizing: border-box;
  }

  .el-input__inner {
    opacity: 0.8 !important;
  }
}

.label {
  font-size: 18px;
}
</style>